package jTopaz;

import org.ietf.jgss.GSSCredential;
import org.globus.myproxy.MyProxy;

/**
Handles logging onto a myproxy server to obtain a proxy credential.
*/
public class MyProxyThread extends Thread{
	
	private String host;
	private String username;
	private String password;
	private GSSCredential cred;
	private String status;
	private boolean error=false;
	
	/**
	@host the name of the myproxy host.
	@username the username.
	@password the account password
	*/
	public MyProxyThread(String host, String  username, String password) {
		
		this.host = host;
		this.username = username;
		this.password = password;
	}
	
	/**
	Attempts to log onto the myproxy server, and then get the credential
	*/
	public void run() {
	
		try {
			MyProxy myProxyInstance = new MyProxy(host, 7512);	
			
			cred = myProxyInstance.get(username, password, 3000);
			status="success";
		}	
		catch (Exception e) {
			System.out.println(e);
			status = "error";
		}
	}
	
	/**
	@return the GSSCredential obtained from the server.
	*/
	public GSSCredential getCred() {
		return cred;
	}
	
	/**
	@return "success" if successfully logged on to my proxy server, "error" if there was a problem
	*/
	public String getStatus() {
		return status;
	}
}